home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / abbrev5.zip / ABLOOKUP.CB < prev    next >
Text File  |  1990-01-23  |  5KB  |  137 lines

  1. #define TRUE 1
  2.  
  3. /*************************************************************************
  4. *                                                                                                *
  5. *     ABLOOKUP.CB                                                                                 *
  6. *                                                                                                  *
  7. *     This contains the utility files used both by "abbrev" and                 *
  8. *     "suffix".  Either package may be used alone in conjunction                 *
  9. *     with this file, and suffix no longer requires the full                     *
  10. *     abbrev to be used.                                                                     *
  11. *                                                                                                  *
  12. *     Larry DeMar   10-19-89.                                                                 *
  13. *                                                                                                *
  14. **************************************************************************
  15. *                                                                        *
  16. *      AB_LOOKUP                                                                                 *
  17. *                                                                                                  *
  18. *      This is called to look up a string in an abbreviation file.             *
  19. *                                                                                                  *
  20. *      Parameter 0 = file part of file name to look in                             *
  21. *      Parameter 1 = string to lookup                                                     *
  22. *      Parameter 2 = global buffer id of system buffer we're using             *
  23. *      Parameter 3 = filename for system buffer                                         *
  24. *                                                                                                  *
  25. *      If parameter 2 is non-zero, then it is the id of a                         *
  26. *      system buffer containing the lookup file.  Else, we                         *
  27. *      create the system buffer.  Read the lookup file in,                         *
  28. *      and put the new buffer id to parameter 2.                                     *
  29. *                                                                                                  *
  30. *      If the string is found to start in column 1 of the                         *
  31. *      lookup file, then the "return string" is on the                             *
  32. *      rest of the line in the file.    The return string                             *
  33. *      is put back to parameter 1.                                                         *
  34. *                                                                                                  *
  35. *      This returns TRUE of FALSE based on whether the lookup                     *
  36. *      succeeded.                                                                                 *
  37. *                                                                        *
  38. *************************************************************************/
  39. ab_lookup (...)
  40. {
  41.     string file_part,
  42.              abbreviation,
  43.              my_search_string,
  44.              sys_file_name;
  45.  
  46.     int orig_buffer,
  47.          system_id,
  48.          return_code;
  49.  
  50.     set_msg_level(1);
  51.  
  52.     get_parm (0, file_part);
  53.     get_parm (1, abbreviation);
  54.     get_parm (2, system_id);
  55.     get_parm (3, sys_file_name);
  56.  
  57.     orig_buffer = inq_buffer ();
  58.     if (system_id)                                          // abbrev file in buffer?                     
  59.         set_buffer (system_id);                       // yep...go there                 
  60.     else     {
  61.         system_id = create_sys_buf (file_part, sys_file_name);    // no...create it. 
  62.         put_parm (2, system_id);                                             // and pass it back. 
  63.     }
  64.     top_of_buffer ();
  65.     sprintf (my_search_string, "<%s[ \t]\\c", abbreviation);
  66.     if (return_code = search_fwd (my_search_string, 1, 0))
  67.         put_parm (1, trim (ltrim (read ())));
  68.     set_buffer (orig_buffer);
  69.     return return_code;
  70. }
  71.  
  72. /*************************************************************************
  73. *                                                                        *
  74. *      CREATE_SYS_BUF                                                                         *
  75. *                                                                                                  *
  76. *      This is called to create the system buffer and read in                     *
  77. *      the abbreviation file.                                                                 *
  78. *                                                                                                  *
  79. *      It returns the id of the buffer it creates.                                     *
  80. *                                                                        *
  81. *************************************************************************/
  82. create_sys_buf (...)
  83. {
  84.     int buf_id;
  85.     string file_part,
  86.          buffer_name;
  87.  
  88.     get_parm (0, file_part);
  89.     get_parm (1, buffer_name);
  90.     buf_id = create_buffer ("abbrev_buf", buffer_name, TRUE);
  91.     set_buffer (buf_id);
  92. //    if(exist(file_part = get_abbrev_file(file_part)))
  93. //        read_file (file_part);         // read in the file          
  94.     read_file(get_abbrev_file(file_part));
  95.     return buf_id;
  96. }
  97.  
  98. /*************************************************************************
  99. *                                                                        *
  100. *      GET_ABBREV_FILE                                                                         *
  101. *                                                                                                  *
  102. *      This is called to return the full path of the abbrev                         *
  103. *      directory file.                                                                         *
  104. *                                                                                                  *
  105. *              1) if BABBREV is in environment, then it is                             *
  106. *                  used as the path.                                                         *
  107. *                                                                                                  *
  108. *              2) if BPATH is in environment, then it is                             *
  109. *                  used as the path.                                                         *
  110. *                                                                                                  *
  111. *              3) otherwise "C:\" is used as the path.                                 *
  112. *                                                                        *
  113. *************************************************************************/
  114.  
  115. #define ENV_1 "BABBREV"
  116. #define ENV_2 "BPATH"
  117. #define DEFAULT_PATH "c:"
  118.  
  119. get_abbrev_file (...)
  120. {
  121.     string abbrev_path,
  122.          file_part;
  123.  
  124.     int semi_spot;
  125.  
  126.     get_parm (0, file_part);
  127.     if ((abbrev_path = inq_environment (ENV_1)) == "")
  128.         if ((abbrev_path = inq_environment (ENV_2)) == "")
  129.             abbrev_path = DEFAULT_PATH;
  130.         else
  131.             if (semi_spot = rindex (abbrev_path, ";"))
  132.                 abbrev_path = substr (abbrev_path, semi_spot + 1);
  133.     return trim (ltrim (abbrev_path)) + ("\\" + file_part);
  134. }
  135.  
  136.  
  137.